<template>
  <div class="login-container">
    <!-- 登录 -->
    <div class="login-wrap">
      <div class="login">
        <div class="loginform">
          <ul class="tab clearFix">
            <li>
              <a href="##" class="current">账户登录</a>
            </li>
          </ul>
          <div class="content">
            <!-- 登录密码与账号输入的地方 -->
            <form action="##">
              <div class="input-text clearFix">
                <span></span>
                <input type="text" placeholder="邮箱/用户名" v-model="form.userName" />
              </div>
              <div class="input-text clearFix">
                <span class="pwd"></span>
                <input type="text" placeholder="请输入密码" v-model="form.password" />
              </div>
              <!-- <div class="input-text clearFix">
                <span class="pwd"></span>
                <input type="text" placeholder="请输入验证码" v-model="form.code" />
                <el-image :src="yanCode" style="width: 120; height: 40px; margin-top:10px;"></el-image>
              </div> -->
              <button class="btn" @click.prevent="login">
                登&nbsp;&nbsp;录
              </button>
            </form>
          </div>
        </div>
      </div>
    </div>
    <!-- 底部 -->
  </div>
</template>

<script>
import { login } from '@/api/index'
// import axios from 'axios';
export default {
  name: "Login",
  data() {
    return {
      form: {
        userName: "admin",
        password: "admin",
        // verifyKey: "",
        email: "",
        isAdmin: 0,
        code: ""
      },
      // yanCode: 'http://192.168.43.194:8001/common/kaptcha',
      //收集账号与密码

    };
  },
  methods: {

    // 刷新验证码
    refreshCaptcha() {
      this.fetchCaptcha();
    },
  },
  methods: {
    demo() {

    },
    // 获取验证码图片
    // fetchCaptcha() {
    //   axios
    //     .get('http://192.168.43.194:8001/common/kaptcha', {
    //       responseType: 'arraybuffer',
    //     })
    //     .then((response) => {
    //       this.form.verifyKey = response.headers['verifykey']
    //     })
    //     .catch((error) => {
    //       console.error('获取验证码失败', error);
    //     });
    // },
    async login() {
      try {
        await this.$store.dispatch("userLogin", this.form)
        let goPath = this.$route.query.redirect || '/home';
        this.$router.push(goPath);
      } catch (error) {
        alert(error.message)
      }

      // login(this.form).then(async (res) => {
      //   localStorage.setItem("token", res.data.token);
      //   await this.$store.dispatch("userLogin", { userName , password });
      // })
      // axios.post('http://192.168.43.194:8001/common/login', this.form)
    }
    //登录按钮
    // async login() {
    //   //整理参数
    //   const { phone, password } = this;
    //   //在发登录请求
    //   try {
    //     //登录成功
    //     await this.$store.dispatch("userLogin", { phone, password });

    //     let goPath = this.$route.query.redirect || '/home';
    //     //跳转到首页
    //     this.$router.push(goPath);
    //   } catch (error) {
    //     alert(error.message);
    //   }
    // },
  },
  mounted() {
    this.fetchCaptcha()
  }
};
</script>

<style lang="less" scoped>
.login-container {
  background: url(./images/logo2.jpg) no-repeat;
  background-size: 100% 100%;

  .login-wrap {
    height: 88vh;
    // background-color: #e93854;

    .login {
      width: 100%;
      height: 487px;
      margin: 0 auto;
      // background: url(./images/logo2.jpg) no-repeat;
      // background-size: 100% 100%;
    }

    .loginform {
      width: 420px;
      height: 406px;
      box-sizing: border-box;
      background: #fff;
      float: right;
      margin-right: 100px;
      top: 45px;
      position: relative;
      padding: 20px;

      .tab {
        li {
          width: 50%;
          float: left;
          text-align: center;

          a {
            width: 100%;
            display: block;
            height: 50px;
            line-height: 50px;
            font-size: 20px;
            font-weight: 700;
            color: #333;
            border: 1px solid #ddd;
            box-sizing: border-box;
            text-decoration: none;
          }

          .current {
            border-bottom: none;
            border-top-color: #28a3ef;
            color: #28a3ef;
          }
        }
      }

      .content {
        width: 380px;
        height: 316px;
        box-sizing: border-box;
        border: 1px solid #ddd;
        border-top: none;
        padding: 18px;

        form {
          margin: 15px 0 18px 0;
          font-size: 12px;
          line-height: 18px;

          .input-text {
            margin-bottom: 16px;

            span {
              float: left;
              width: 37px;
              height: 32px;
              border: 1px solid #ccc;
              background: url(~@/assets/icons.png) no-repeat -10px -201px;
              box-sizing: border-box;
              border-radius: 2px 0 0 2px;
            }

            .pwd {
              background-position: -72px -201px;
            }

            input {
              width: 302px;
              height: 32px;
              box-sizing: border-box;
              border: 1px solid #ccc;
              border-left: none;
              float: left;
              padding-top: 6px;
              padding-bottom: 6px;
              font-size: 14px;
              line-height: 22px;
              padding-right: 8px;
              padding-left: 8px;

              border-radius: 0 2px 2px 0;
              outline: none;
            }
          }

          .setting {
            label {
              float: left;
            }

            .forget {
              float: right;
            }
          }

          .btn {
            background-color: #28a3ef;
            padding: 6px;
            border-radius: 0;
            font-size: 16px;
            font-family: 微软雅黑;
            word-spacing: 4px;
            border: 1px solid #28a3ef;
            color: #fff;
            width: 100%;
            height: 36px;
            margin-top: 25px;
            outline: none;
            cursor: pointer;
          }
        }

        .call {
          margin-top: 30px;

          ul {
            float: left;

            li {
              float: left;
              margin-right: 5px;
            }
          }

          .register {
            float: right;
            font-size: 15px;
            line-height: 38px;
          }

          .register:hover {
            color: #4cb9fc;
            text-decoration: underline;
          }
        }
      }
    }
  }

  .copyright {
    width: 1200px;
    margin: 0 auto;
    text-align: center;
    line-height: 24px;
    color: #fff;

    ul {
      li {
        display: inline-block;
        border-right: 1px solid #e4e4e4;
        padding: 0 20px;
        margin: 15px 0;
      }
    }
  }
}
</style>